#!/usr/bin/perl
#save-group.cgi

require "./mdmgroups-lib.pl";
&ReadParse();
&foreign_require("groups","accounts.pl");

my $groupname = $in{'oldname'};
my $newname = $in{'gpname'};
my $memlist = $in{'listinput'};
my $savetype = $in{'savetype'};
my $error_msg=&foreign_call("groups","check_simbol_uname",$newname);
my $mdminfoaddr=&get_groupinfo;
my %mdminfo=%$mdminfoaddr;
my @grplist = split (/,/,$mdminfo{'[group]'});
if ($error_msg){
	&error($error_msg);
}

foreach (@grplist){
	if ($_ eq $newname){
		if ($groupname ne $newname){
			&error($text{'samename'});
		}
	}
}
#&header($text{'edit_title'}, "", "index", 0, 1);
if($savetype eq "new"){
	&save_new_grp($newname,$memlist);
}elsif($savetype eq "old"){
	&save_old_grp($groupname,$newname,$memlist);
}else{
	&error("Accident!");
}

&redirect("index.cgi");